import wsRequest from './websocket.js'
export default {
	getWebsocket(val) {
		let url1 = ''
		if (uni.getStorageSync('serveList')) {
			uni.getStorageSync('serveList').forEach((item, index) => {
				if (item.switch) {
					url1 = item.ipAddress
				}
			})
			let url = url1.split(":")[0] + ':9100'
			let infoData = {
				userId: val,
				type: "heartbeat"
			}
			this.websocket = new wsRequest("ws:" + url + "/chat", infoData, 10 * 1000)
			setTimeout(() => {
				this.websocket.send(JSON.stringify(infoData))
			}, 300)
		}
	},
	closeWebsocket() {
		if (this.websocket) {
			this.websocket.close()
		}
	}
}